package com.example.demo.controller;

import com.example.demo.entity.Student;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("my")
public class MyController {
    @Autowired
    private StudentService studentService;
    @RequestMapping("findAllStudents")
    public String findAllStudents(Model m){
        List<Student> students = studentService.findAllStudent();
        m.addAttribute("students",students);
        return "list";
    }

    @RequestMapping("toStr")
    @ResponseBody
    public List<Student> toStr(){
        return studentService.findAllStudent();
    }
}
